<%@ page language="java"  pageEncoding="utf-8"%>
<%@taglib uri="/WEB-INF/struts-tags.tld" prefix="s"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发邮件</title>
<%@include file="../common/jscss.jsp" %>
<style>
	.add_attachment_wrap{position:absolute; top:325px; left:180px;*top:330px;}
</style>
</head>

<body>
	<!-- head -->
	<%@include file="../common/header.jsp" %>
    <!-- head--end -->
    <div class="content">
    	<div class="body_wrap clearfix">
            <div class="com_left">
            	<div class="com_pd_s1">
                	<div class="box_s2">
                    	<div class="title"><img src="images/other/icon_10.jpg" /><span>邮件发布</span></div>
                        <div class="content">
                        	<div class="p_upfile">
                        	<form id="send_mail_form" action="mail!send.do" method="post">
                        	<table class="form_info">
                            	<tr>
                                	<td width="87" class="col1">接收人：</td>
                                    <td><input type="text" id="rmember" name="message.rmember"  class="def_txt_s1" value="<s:property value="#request.rmember"/>"/><input type="hidden" id="detail_items" value="<s:property value="message.rmember"/>"/><input type="button" id="contact_btn"  value="添加" class="def_btn_s1 ml20" /></td>
                                </tr>
                                <tr>
                                	<td width="87" class="col1">标题：</td>
                                    <td><input type="text" name="message.title" id="title" class="def_txt_s1" value="<s:property value="message.title"/>"/></td>
                                </tr>
                                <tr>
                                	<td width="87" class="col1 vt">内容：</td>
                                    <td>
                                    	<textarea class="def_ta" id="content" name="message.content"><s:property value="message.content"/></textarea>
                                        <div class="operate">
                                        	<input type="button"  id="send_mail" value="发送" class="def_btn_s1" />
                                        	<input type="button" onclick="window.location.href='mail!receivebox.do'"   value="取消" class="def_btn_s1" style="margin-right: 10px;"/>
                                        	<!--<a href="javascript:void(0);" class="attachment" onclick="myFile.click();">添加附件</a>-->
                                        	
                                        	<div><input type="checkbox" id="is_send_msg"/><span>短信通知</span></div>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                	<td></td>
                                	<td >
                                    	<ul class="attach_list" id="attach_list">
                                    	<s:iterator id="attach" value="message.attachList" status="status">
                                    		<li><a class="a1" href="<s:property value="#request.basePath"/><s:property value="path"/>" target="_blank"><s:property value="name"/></a><a class="a2" href="javascript:void(0);" filePath="<s:property value="path"/>" class="cancl" onclick="cancelAttach(this)">取消</a></li>
	                                	</s:iterator>
                                    	</ul>
                                    </td>
                                </tr>
                            </table>
                            </form>
                            <form action="mail!uploadAttach.do" id="attach_upload" method="post" enctype="multipart/form-data">
                            <div class="add_attachment_wrap">
                               	<a href="javascript:void(0);" class="attachment" style="top: 0px;">添加附件</a><input style="top: 0px;" type="file" onchange="uploadAttach('<s:property value="#request.basePath"/>');" name="attach" class="file_load" id="myFile" />
                               </div>
                            </form>
                           </div>
                        </div>
                    </div>
                    
                </div>
            </div>
            
            <!-- right -->
            <%@include file="right.jsp"%>
            <!--right--end-->
            <br class="clear" />
        </div>
    </div>
    <div class="contact_box" id="contact" style="display:none">
    	<div class="title">
        	<a href="#" class="contact_close">关闭</a>
        	<span>从联系人中添加</span>
            
        </div>
        <div class="contact_content clearfix">
        	<div class="contact_list_box">
            	<span class="tip">联系人</span>
                <div class="show_contact_list">
                	<ul class="c_show_list">
                    	<s:iterator id="roleTree" value="roleTree">
                    	<s:if test="#roleTree.hasMember">
                    	<li>
                        	<a href="#" class="second_contact_sorts"><b class="fold_btn_1"></b><span><s:property value="name"/></span></a><a href="#" class="sencond_contact_sorts_nums">(全选)</a><a href="#" class="group_select" cid="<s:property value="id"/>" csorts="G" name="<s:property value="name"/>">(选择组)</a>
                        	<s:if test="(#roleTree.roleList != null && #roleTree.roleList.size() > 0) || (#roleTree.memberList != null && #roleTree.memberList.size() > 0)">
                        	<ul class="second_sorts ml5" style="display:none;">
                        		<s:iterator value="#roleTree.roleList" id="roleTree2">
                        		<s:if test="#roleTree2.hasMember">
                            	<li>
                                	<a href="#" class="third_contact_sorts"><s:property value="name"/></a><a href="#" class="third_contact_sorts_nums ml5">(全选)</a><a href="#" class="group_select" cid="<s:property value="id"/>" csorts="G" name="<s:property value="name"/>">(选择组)</a>
                                    <s:if test="(#roleTree2.roleList != null && #roleTree2.roleList.size() > 0) || (#roleTree2.memberList != null && #roleTree2.memberList.size() > 0)">
                                    <ul class="third_sorts ml15" style="display:none;">
                                    	<s:iterator value="#roleTree2.roleList" id="roleTree3">
                                    	<s:if test="#roleTree3.hasMember">
                                    	<li>
                                        	<a href="#" class="contact_sorts"><s:property value="name"/></a><a href="#" class="contact_sorts_nums ml5">(全选)</a><a href="#" class="group_select" cid="<s:property value="id"/>" csorts="G" name="<s:property value="name"/>">(选择组)</a>
                                            
                                            <s:if test="#roleTree3.memberList != null && #roleTree3.memberList.size() > 0">
                                            <ul class="contact_child_list" style=" display:none;">
                                            <s:iterator value="#roleTree3.memberList" id="memberList">
                                                <li><a href="#" csorts="P" cid="<s:property value="id"/>"><s:property value="username"/></a></li>
                                             </s:iterator>
                                            </ul>
                                           </s:if>
                                        </li>
                                        </s:if>
                                        </s:iterator>
                                       <s:if test="#roleTree2.memberList != null && #roleTree2.memberList.size() > 0">
		                               		<s:iterator value="#roleTree2.memberList" id="member">
		                               			<ul class="contact_child_list" style="display: block; ">
		                                            <li><a style="padding: 0" href="#" csorts="P" cid="<s:property value="id"/>"><s:property value="username"/></a></li>
		                                         </ul>
		                               			
		                               		</s:iterator>
		                               </s:if>
                                    </ul>
                                    </s:if>
                                </li>
                                </s:if>
                                </s:iterator>
                               	<s:if test="#roleTree.memberList != null && #roleTree.memberList.size() > 0">
                               		<s:iterator value="#roleTree.memberList" id="member">
                               			<ul class="contact_child_list" style="display: block; ">
                                            <li><a style="padding: 0" href="#" csorts="P" cid="<s:property value="id"/>"><s:property value="username"/></a></li>
                                         </ul>
                               			
                               		</s:iterator>
                               </s:if>
                            </ul>
                        	</s:if>
                            
                        </li>
                        </s:if>
                        </s:iterator>
                     
                    </ul>
                </div>
            </div>
            
            <span class="arrow">
            	
            </span>
            
            <div class="contact_list_box">
            	<div class="tip"><span>添加到</span><a href="javascript:;" id="c_cancl" style="float: right;color: #98844F">移除全部</a></div>
                <div class="show_contact_list">
                	<ul class="c_insert_list" id="accept_item">
                    </ul>
                </div>
            </div>
        </div>
        <div class="contact_btn_box">
        	<a href="javascript:void(0);" class="c_btn" id="c_insure">确定</a><!--<a href="javascript:void(0);" class="c_btn" id="c_cancl">取消</a>		
        --></div>
    </div>
    <!-- body -->
    <script type="text/javascript">
    	$(function(){
    		$.defUnit.contactBox.Defaults={
				acceptID:"rmember"	
			}
			$.defUnit.contactBox();
			$("#contact_btn").click(function(){
				$.defUnit.popDiv({
					tcID:"contact"	
				});
					
			});		
			
			$("#send_mail").click(function(){
				sendMail();
			});
		});
    
    	function sendMail(){
    		
    		var rmember = $("#detail_items").val();
    		var title = $("#title").val();
    		var content = $("#content").val();
    		var isSendMsg = false;
    		if($("#is_send_msg").attr("checked")){
    			isSendMsg = true;
    		}
    		if(rmember == null || rmember == ""){
    			alert("收件人不能为空！");
    			return false;
    		}
    		if(title == null || title == ""){
    			alert("标题不能为空！");
    			return false;
    		}
    		if(content == null || content == ""){
    			alert("内容不能为空！");
    			return false;
    		}
    		var attachList = new Array();
    		$("#send_mail").unbind("click");
    		$("#attach_list li").each(function(){
    			var fileName = $(this).find("a.a1").text();
    			var filePath = $(this).find("a.a2").attr("filePath");
    			attachList.push({
    				name:fileName,
    				path:filePath
    			});
    		});
    		$.post("mail!send.do",{
    			'message.rmember':rmember,
    			'message.title':title,
    			'message.content':content,
    			'message.isSendMsg':isSendMsg,
    			'message.attachs':$.toJSON(attachList)
    		},function(data){
    			if(data!=null){
    				var ret = $.parseJSON(data);
    				if(ret.success == 'true'){
						window.location.href='mail!sendbox.do';
    				}
    			}
    		});
    	//	$("#send_mail_form").submit();
    	//	return false;
    	}
    	
    	
    	
    </script>
</body>
</html>
